<?php

require_once("../data/common.php");
if(!isset($_GET['id'])) {
	die("I need ID!");
}

if ($user->logged_in == 1) {
} else {
	die("Not logged in.");
}

	$sql = "SELECT 
			tr.device_id AS device_id, 
			tr.first_id AS first_id, 
			tr.last_id AS last_id, 
			tr.track_id AS track_id, 
			u.username AS username, 
			u.id AS user_id
		FROM 
			users u, 
			tracks tr, 
			users_devices ud
		WHERE 
		tr.track_id = ? AND
			(	tr.device_id=ud.id AND
				ud.user_id=u.id);";

$stmt = $dbh->prepare($sql);
$stmt->execute(array($_GET['id']));
$row = $stmt->fetch();
$stmt = null;
if ($row["user_id"] != $user->logged_in_user_id) {
	die("Security violation.");
}
/*echo '<pre>';
var_dump($row);
echo '</pre>';*/

$id = BaseIntEncoder::encode($_GET['id']);
if ($id === FALSE) {
	echo "Unfortunately this installation seems to be missing some parts which are required to generate the link. Please inform the administrator about this.";
} else {
	echo "You can share this track to your friends and other map-programs by using the following link:<br>";
	echo '<form>';
	echo '<input type="text" size="60" name="link" value="'.$site_url."/share_track.php?id=".$id.'" onClick="javascript:this.form.link.focus();this.form.link.select();">';
	echo '</form>';
}
//Here will be links in future to things like facebook app

?>
